package com.demo.message_retry;

import cn.lingyangwl.framework.tool.core.exception.BizException;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 用于测试当重试一定次数之后, 消息转发到错误消息队列中
 * @author shenguangyang
 */
@Slf4j
@Component
@RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue(value = "test.error.queue", durable = "true"), key = "test.error.key01",
                exchange = @Exchange(value = "test.error.exchange", type = ExchangeTypes.TOPIC))
})
public class TestError01Listener {

    @RabbitHandler
    public void onMessage(String data, Channel channel, Message message) {
        log.info("开始消费: {}", data);
        throw new BizException("业务异常");
    }
}
